package ee.homework.first;

import java.util.Arrays;
import java.util.Random;

public class QuickSortImpl {

	private Random random = new Random();
	private int arrLength = 1000000;

	public static void main(String[] args) {
		QuickSortImpl qsi = new QuickSortImpl();
		qsi.quickSort();
		qsi.javaSort();
	}

	private void quickSort() {
		Quicksort quickSort = new Quicksort();
		int[] arr = new int[arrLength];
		int[] randArr = new int[arrLength];
		for (int j = 0; j < 5; j++) {
			for (int i = 0; i < arr.length; i++) {
				int var = random.nextInt(arrLength + 1);
				arr[i] = var;
				randArr[i] = var;
			}
			System.out.println("Cycle " + (j + 1));
			// quickSort.printList(arr);
			long time = System.currentTimeMillis();
			// quickSort.quickSort(arr);
			// System.out.println("Quicksort sorting time: "
			// + (System.currentTimeMillis() - time) + "ms");
			// time = System.currentTimeMillis();
			quickSort.randomizedQuickSort(arr);
			System.out.println("Randomized quicksort sorting time: "
					+ (System.currentTimeMillis() - time) + "ms");
		}
	}

	private void javaSort() {
		int[] arr = new int[arrLength];
		for (int j = 0; j < 5; j++) {
			for (int i = 0; i < arr.length; i++) {
				int var = arrLength - i;
				arr[i] = var;
			}
			System.out.println("Cycle " + (j + 1));
			// quickSort.printList(arr);
			long time = System.currentTimeMillis();
			Arrays.sort(arr);
			System.out.println("Java sort sorting time: "
					+ (System.currentTimeMillis() - time) + "ms");
		}
	}
}
